<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>检验任务看板</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 看板标题组件 -->
    <vue2-report-header :title="title"></vue2-report-header>
    <div style="padding:10px;">
      <el-form :inline="true" :model="queryInfo" :label-position="'left'">
        <el-form-item label="主制分厂:">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择" filterable style="width:140px;">
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-form-item label="工序类型:">
            <el-select v-model="queryInfo.spectype" placeholder="请选择" filterable clearable style="width:120px;">
              <el-option v-for="item in spectypeList" :key="item.spectype" :label="item.spectype"
                :value="item.spectype">
              </el-option>
            </el-select>
          </el-form-item>
          <template slot="label">
            <el-popover placement="top-start" title="工序类型定义如下" width="600" trigger="hover">
              <i class="el-icon-info" slot="reference"></i>
              <p>【普通工序】：既不是检序也不是转工序。</p>
              <p>【检验工序】：仅是检序，但不是转工序。</p>
            </el-popover>
          </template>
        </el-form-item>

        <el-form-item label="报工时间范围:">
          <el-select v-model="queryInfo.days" placeholder="请选择" style="width: 100px;" clearable>
            <el-option :key="'7'" :label="'7天内'" :value="'7'"></el-option>
            <el-option :key="'10'" :label="'10天内'" :value="'10'"></el-option>
            <el-option :key="'30'" :label="'30天内'" :value="'30'"></el-option>
            <el-option :key="'90'" :label="'90天内'" :value="'90'"></el-option>
            <el-option :key="'不限'" :label="'不限'" :value="''"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="处理状态">
          <el-select v-model="queryInfo.status" placeholder="请选择" clearable filterable style="width:120px;">
            <el-option :key="'待检'" :label="'待检'" :value="'待检'"></el-option>
            <el-option :key="'待处理'" :label="'待处理'" :value="'待处理'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop='productname' label="零件号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入" :trigger-on-focus="false"
            style="width:200px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containername' label="流水卡号:">
          <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入" :trigger-on-focus="false"
            style="width:200px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="handleBtnSearch" icon="el-icon-search" size="small">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
          <template slot="label">
            <el-popover placement="top-start" title="看板查询规则说明:" width="300" trigger="hover">
              <i class="el-icon-info" slot="reference"></i>
              <p>1. 不显示已入库批次。</p>
              <p>2. 只查询已报工未检验批次。</p>
            </el-popover>
          </template>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="40"></el-table-column>
        <el-table-column label="工艺信息" width="80">
          <template slot-scope="scope">
            <el-popover trigger="click" placement="top" width="400">
              <p>
                零件号: {{scope.row.productname}}
              </p>
              <p>
                零件版本: {{scope.row.productrevision}}
              </p>
              <p>
                工艺路线: {{scope.row.workflowname}}
              </p>
              <p>
                工艺版本: {{scope.row.workflowrevision}}
              </p>
              <p>当前工序: {{scope.row.currentspec}}</p>
              <div slot="reference">
                <el-link type="primary">查看</el-link>
              </div>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="流水卡号" prop="containername" show-overflow-tooltip></el-table-column>
        <el-table-column label="零件名称" prop="productdescription" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="工序" prop="workflowstepname" width="140" show-overflow-tooltip></el-table-column>
        <el-table-column label="工序类型" prop="spectype" width="95" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag v-if="scope.row.spectype === '普通工序'">{{scope.row.spectype}}</el-tag>
            <el-tag v-else type="danger">{{scope.row.spectype}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="数量" prop="reportqty" width="60" show-overflow-tooltip></el-table-column>
        <el-table-column label="工区" prop="workcentername" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="工人报工时间" prop="reportdate" width="120" show-overflow-tooltip>
          <template slot-scope="scope">
            <div v-if="scope.row.reportdate">
              <i class="el-icon-time"></i>
              <span>{{scope.row.reportdate.split('T')[0]}}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="等待时间" width="120" show-overflow-tooltip>
          <template slot-scope="scope">
            <div v-if="scope.row.delayhours !== '0'" style="color:red;">
              <i class="el-icon-time"></i>
              <span>{{scope.row.delayhours}}小时</span>
            </div>
            <div v-else>
              <i class="el-icon-time"></i>
              <span>{{scope.row.delayhours}}小时</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="待检人" prop="tochecker" width="80" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="检验员" prop="fullname" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="处理状态" width="100">
          <template slot-scope="scope" v-if="scope.row.status">
            <div v-if="scope.row.status !== '待检'">
              <el-tag>{{scope.row.status}}</el-tag>
            </div>
            <div v-else>
              {{scope.row.status}}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="其他等待时间" prop="otherdalayhours" width="120" show-overflow-tooltip>
          <template slot-scope="scope">
            <div v-if="scope.row.otherdalayhours !== '0'">
              <span>{{scope.row.otherdalayhours}}小时</span>
            </div>
            <div v-else>
              <span>0</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="备注" prop="notes" width="120" show-overflow-tooltip></el-table-column>
      </el-table>

      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
        :page-sizes="[14,50,100]" :page-size="pageSize" layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>
  <script type="module">
    import { getParams, exportExcelData, fetchSuggestion } from '../Scripts/hooks/useCommonMethod.js';
    import { getFactoryListByCode, getUserInfo } from '../Scripts/hooks/fetchAPI.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        loading: false,
        loadingText: '拼命加载中',
        title: '',// 看板标题
        queryInfo: {
          factoryid: '', //主制分厂
          factoryname: '', //分厂
          spectype: '',// 工序类型
          status: '', // 处理状态
          containername: '',
          days: '7',
          productname: '',
          factorycode: ''
        },
        currentPage: 1,//当前页
        pageSize: 14, //每页显示条数
        total: 0,// 总条数
        dataList: [],
        factoryList: [],
        userInfo: {},
        spectypeList: [
          { spectype: '普通工序' },
          { spectype: '检验工序' }
        ]
      },
      methods: {
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback, triggerLength: 1 });
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback, triggerLength: 1 });
        },
        //查询数据
        async getData(currentpage) {
          this.loading = true;
          this.loadingText = '数据查询中...'
          const { data: { data, meta, total } } = await axios({
            method: 'post',
            url: `../handler/board/ContainerCheckInfoLookBoard.ashx?action=getData&currentPage=${this.currentPage}&pageSize=${this.pageSize}`,
            data: {
              action: 'getData',
              ...this.queryInfo,
              currentPage: this.currentPage,
              pageSize: this.pageSize
            }
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.dataList = data;
          this.total = total;
        },
        // 导出excel
        async getExportExcel() {
          const config = {
            url: '../handler/board/ContainerCheckInfoLookBoard.ashx?action=getExportExcel',
            data: { action: 'getExportExcel', ...this.queryInfo }
          }
          exportExcelData(config, this);
        },
        //监听 currentpage 改变
        handleCurrentChange(newPage) {
          this.currentPage = newPage;
          this.getData();
        },
        //监听 pagezie 改变
        handleSizeChange(newSize) {
          this.pageSize = newSize;
          this.getData();
        },
        handleBtnSearch() {
          this.currentPage = 1
          this.getData()
        }
      },
      async mounted() {
        this.userInfo = await getUserInfo({ employeeid: getParams("uid") });
        this.factoryList = await getFactoryListByCode({ factoryCode: '601|607|609|600|608|602' });

        if (this.userInfo.factoryid && this.factoryList.some(item => item.factoryid === this.userInfo.factoryid)) {
          const { factoryid, factoryname, factorycode } = this.userInfo;
          this.queryInfo.factoryid = factoryid;
          this.queryInfo.factoryname = factoryname;
          this.queryInfo.factorycode = factorycode;
        } else {
          this.queryInfo.factoryid = this.factoryList[0].factoryid;
          this.queryInfo.factoryname = this.factoryList[0].factoryname;
          this.queryInfo.factorycode = this.factoryList[0].attributevalue;
        }
        this.title = `${this.queryInfo.factoryname}检验任务看板`;
        document.title = this.title;
        this.getData();
      },
      watch: {
        queryInfo: {
          handler() {
            this.currentPage = 1;
            this.queryInfo.factoryname = this.factoryList.filter(item => item.factoryid === this.queryInfo.factoryid)[0].factoryname;
            this.queryInfo.factorycode = this.factoryList.filter(item => item.factoryid === this.queryInfo.factoryid)[0].attributevalue;
            this.title = `${this.queryInfo.factoryname}检验任务看板`;
            document.title = this.title;
          },
          deep: true
        }
      }
    })
  </script>
</body>

</html>